package com.ruoyi.activiti.modeler.controller;

import com.ruoyi.activiti.modeler.domain.ActReModel;
import com.ruoyi.activiti.modeler.service.IActReModelService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【请填写功能名称】Controller
 * 
 * @author suguowen
 * @date 2021-01-07
 */
@Controller
@RequestMapping("/suguowen/model")
public class ActReModelController extends BaseController
{
    private String prefix = "suguowen/model";

    @Autowired
    private IActReModelService actReModelService;

//    @RequiresPermissions("suguowen:model:view")
    @GetMapping()
    public String model()
    {
        return prefix + "/model";
    }

    /**
     * 查询【请填写功能名称】列表
     */
//    @RequiresPermissions("suguowen:model:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ActReModel actReModel)
    {
        startPage();
        List<ActReModel> list = actReModelService.selectActReModelList(actReModel);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
//    @RequiresPermissions("suguowen:model:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ActReModel actReModel)
    {
        List<ActReModel> list = actReModelService.selectActReModelList(actReModel);
        ExcelUtil<ActReModel> util = new ExcelUtil<ActReModel>(ActReModel.class);
        return util.exportExcel(list, "model");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
//    @RequiresPermissions("suguowen:model:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ActReModel actReModel)
    {
        return toAjax(actReModelService.insertActReModel(actReModel));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ActReModel actReModel = actReModelService.selectActReModelById(id);
        mmap.put("actReModel", actReModel);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
//    @RequiresPermissions("suguowen:model:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ActReModel actReModel)
    {
        return toAjax(actReModelService.updateActReModel(actReModel));
    }

    /**
     * 删除【请填写功能名称】
     */
//    @RequiresPermissions("suguowen:model:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(actReModelService.deleteActReModelByIds(ids));
    }
}
